import os.path
import sys
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager

#创建一个浏览器对象
class Driver:
    driver = ""
    def __init__(self):
        driver_path = EdgeChromiumDriverManager().install()
        edge_options = Options()
        edge_options.add_argument( "--remote-allow-origins=*" )
        # 2. 创建浏览器驱动对象访问浏览器
        self.driver = webdriver.Edge( service=Service( driver_path ), options=edge_options )
        #隐式等待
        self.driver.implicitly_wait(3)

   #创建屏幕截图
    def getScreenShot(self):
        dirname = datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("../images/"+dirname):
            os.makedirs("../images/"+dirname)
    #图片路径：../images/LoginSucTest(方法名)-2025-06-29/2025-06-29-125940.png
        filename = sys._getframe().f_back.f_code.co_name+datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

ForumDriver = Driver()

